//
//  MyselfViewController.m
//  Findif
//
//  Created by Cicel Chen on 2018/10/18.
//  Copyright © 2018年 Cicel Chen. All rights reserved.
//

#import "MyselfViewController.h"
#import "MyselfHeaderView.h"
#import "SettingTableViewCell.h"
#import "AppDelegate.h"
#import "LoginViewController.h"
#import "AppDelegate.h"
#import "ShopTabBarController.h"
#import "MyCollectionViewController.h"
#import "EditViewController.h"
#import "MyOrderViewController.h"
#import "MoneyViewController.h"
#import "ApplyforShopViewController.h"
#import "MyBankCardViewController.h"
#import "MyAttentionViewController.h"
#import "MyfansViewController.h"
#import "SendSuggestViewController.h"
#import "MerchantsStatusViewController.h"
#import "NSNotiViewController.h"
#import <JMessage/JMessage.h>
#import "ChatRoomViewController.h"
#import "CommitViewController.h"
#import "CouponView.h"
#import "ShopDetailsViewController.h"
#import "MyselfCollectionViewCell.h"
#import "MyAlbumViewController.h"
#import "MyGroupActiveViewController.h"
#import "MyDynamicViewController.h"
#import "MyShieldViewController.h"
#import "MyDiscountViewController.h"
#import "MyIntegralViewController.h"

@interface MyselfViewController ()<MyselfHeaderViewDelegate,HomeCouponViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource>

@property (nonatomic, weak)UIScrollView * scrollView;
@property (nonatomic, weak)UIView * container;
@property (nonatomic, weak)UIButton * leftButton;
@property (nonatomic, weak)UIButton * rightButton;
@property (nonatomic, strong)NSArray * titleArray;
@property (nonatomic, strong)NSArray * imgArray;
@property (nonatomic, strong)MyselfHeaderView * headerView;
@property (nonatomic, strong)NSDictionary * dict;
@property (nonatomic, weak)UIToolbar *toolbar;
@property (nonatomic, weak)UIView * helpView;
@property (nonatomic, strong)CouponView * couponView;
@property (nonatomic, weak)UIView * backView;
@property (nonatomic, weak)UICollectionView * collectionView;
@property (nonatomic, weak)UIButton * outButton;

@end

@implementation MyselfViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self loadData];
    [self.navigationController setNavigationBarHidden:YES animated:animated];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];

    [self.navigationController setNavigationBarHidden:NO animated:animated];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = ColorWithRGB(0xEFF0F1);
    self.navigationItem.title = @"";
//    @[@"我的优惠券",@"我的收藏",@"我的关注",@"我的粉丝",@"我的银行卡",@"反馈",@"登出"]
    self.titleArray = @[@"我的优惠券",@"我的银行卡",@"我的相册",@"我的动态",@"我的收藏",@"我的活动",@"我的反馈",@"我的屏蔽"];
    self.imgArray = @[@"我的优惠券",@"我的银行卡",@"我的相册",@"我的动态",@"我的收藏",@"我的活动",@"我的反馈",@"我的屏蔽"];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(removeCouponView) name:@"clickCloseButton" object:nil];
    
    [self setupUI];
}


- (void)loadData{
    
    NSString *ID = DEF_GET_OBJECT(@"id");
    
    [[ZRNetworkTool sharedTool] getUserInfoResultWithUser_id:ID WithExamine_user_id:@"" WithBlock:^(BOOL success, id responseData) {
        
//        NSLog(@"responseData===%@",responseData);
        if (success) {
            self.dict = responseData[@"data"];
            self.headerView.dict = self.dict;

            if([[self.dict allKeys] containsObject:@"merchants_id"]){
                
                NSString * merchants_id = self.dict[@"merchants_id"];
                DEF_SET_OBJECT(merchants_id, @"shopid");
            }
        }
    }];
    
    [[ZRNetworkTool sharedTool] judgeUserNoticeWithUser_id:ID ResultWithBlock:^(BOOL success, id responseData) {
        
        if (success) {
            
            self.rightButton.selected = YES;
        }else{
            
            self.rightButton.selected = NO;
        }
    }];
}


- (void)setupUI {
   
    UIScrollView * scrollView = [[UIScrollView alloc] init];
    
    scrollView.showsVerticalScrollIndicator = NO;
    
    self.scrollView = scrollView;
    
    [self.view addSubview:self.scrollView];
    
    UIView * container = [UIView new];
    
    self.container = container;
    
    [scrollView addSubview:self.container];
    
    
    UIButton * leftButton = [UIButton new];

    [leftButton setImage:[UIImage imageNamed:@"客服(1)"] forState:UIControlStateNormal];
    [leftButton addTarget:self action:@selector(clickSeverButton:) forControlEvents:UIControlEventTouchUpInside];

    self.leftButton = leftButton;

    [self.view addSubview:leftButton];
    
    //系统消息
    UIButton * rightButton = [UIButton new];
    
    [rightButton setImage:[UIImage imageNamed:@"系统消息"] forState:UIControlStateNormal];
    [rightButton setImage:[UIImage imageNamed:@"系统消息3"] forState:UIControlStateSelected];
    [rightButton addTarget:self action:@selector(clickSeverButton:) forControlEvents:UIControlEventTouchUpInside];
    rightButton.selected = NO;
    
    self.rightButton = rightButton;
    
    [self.view addSubview:rightButton];

    self.headerView =  [[MyselfHeaderView alloc] initWithFrame:CGRectMake(0, topHeight, kScreenW, 355 * SCREENH6)];
    self.headerView.myselfHeaderViewDelegate = self;
    self.headerView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pushToEditVC)];
    [self.headerView addGestureRecognizer:tap];

    
    [self.view addSubview:self.headerView];
    
    //1.初始化layout
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    
    layout.itemSize =CGSizeMake(70 * SCREENH6, 60 * SCREENH6);
    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    
    //设置collectionView滚动方向
//    [layout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
    //2.初始化collectionView
    UICollectionView * collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(15 * SCREENH6, self.headerView.bottom, 345 * SCREENH6, 150 * SCREENH6) collectionViewLayout:layout];
    
    collectionView.backgroundColor = ColorWithRGB(0xEFF0F1);
    collectionView.showsHorizontalScrollIndicator = NO;
    //3.注册collectionViewCell
    //注意，此处的ReuseIdentifier 必须和 cellForItemAtIndexPath 方法中 一致 均为 cellId
    [collectionView registerClass:[MyselfCollectionViewCell class] forCellWithReuseIdentifier:@"MyselfCollectionViewCell"];
    //4.设置代理
    collectionView.delegate = self;
    collectionView.dataSource = self;
    //    [collectionView setContentOffset:CGPointMake(-30 * SCREENH6, 0)];
    
    self.collectionView = collectionView;
    
    [self.scrollView addSubview:self.collectionView];
    
    UIButton * outButton = [UIButton new];
    
    [outButton setTitle:@"退出登录" forState:UIControlStateNormal];
    [outButton setTitleColor:ColorWithRGB(0xF44336) forState:UIControlStateNormal];
    [outButton addTarget:self action:@selector(clickOutButton) forControlEvents:UIControlEventTouchUpInside];
    outButton.titleLabel.font = [UIFont systemFontOfSize:18 * SCREENH6];
    
    self.outButton = outButton;
    
    [self.scrollView addSubview:self.outButton];
}

#pragma mark collectionView代理方法

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
    return self.titleArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    MyselfCollectionViewCell *cell = (MyselfCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"MyselfCollectionViewCell" forIndexPath:indexPath];
    //设置数据
    cell.showLabel.text = self.titleArray[indexPath.row];
    NSString * img = self.imgArray[indexPath.row];
    cell.iconImageView.image = [UIImage imageNamed:img];
    
    return cell;
}


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.row == 0) {
        
//        [self didLeftNavButton];
        HiddenBar;

        MyDiscountViewController * myDisVC = [MyDiscountViewController new];

        [self.navigationController pushViewController:myDisVC animated:YES];

        ShowBar;
    }else if (indexPath.row == 1){
        
        HiddenBar;
        
        MyBankCardViewController * myBankVC = [MyBankCardViewController new];
        
        [self.navigationController pushViewController:myBankVC animated:YES];
        
        ShowBar;
    }else if (indexPath.row == 2){
        //我的相册
        HiddenBar;
        
        MyAlbumViewController * myAlbumVC = [MyAlbumViewController new];
        
        myAlbumVC.type = @"1";
        
        [self.navigationController pushViewController:myAlbumVC animated:YES];
        
        ShowBar;
    }else if (indexPath.row == 3){
        //我的动态
        HiddenBar;
        
        MyDynamicViewController * dynamicVC = [MyDynamicViewController new];
        
        [self.navigationController pushViewController:dynamicVC animated:YES];
        
        ShowBar;
    }else if (indexPath.row == 4){
        //我的收藏
        HiddenBar;
        
        MyCollectionViewController * myCollectionVC = [MyCollectionViewController new];
        
        [self.navigationController pushViewController:myCollectionVC animated:YES];
        
        ShowBar;
    }else if (indexPath.row == 5){
        //我的活动
        HiddenBar;
        
        MyGroupActiveViewController * activeVC = [MyGroupActiveViewController new];
        
        [self.navigationController pushViewController:activeVC animated:YES];
        
        ShowBar;
    }else if (indexPath.row == 6){
        //我的反馈
        HiddenBar;
        
        SendSuggestViewController * suggestVC = [SendSuggestViewController new];
        
        [self.navigationController pushViewController:suggestVC animated:YES];
        
        ShowBar;
    }else if (indexPath.row == 7){
        //我的屏蔽
        HiddenBar;
        
        MyShieldViewController * shieldVC = [MyShieldViewController new];
        
        [self.navigationController pushViewController:shieldVC animated:YES];
        
        ShowBar;
    }
}


- (void)viewDidLayoutSubviews{
    
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    
    [self.container mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.scrollView);
        make.width.equalTo(self.scrollView);
    }];
    
    [self.leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.view).offset(-15 * SCREENH6);
        make.top.mas_equalTo(self.view).offset(kStatusBarHeight + 10 * SCREENH6);
        make.width.mas_equalTo(22 * SCREENH6);
        make.height.mas_equalTo(19 * SCREENH6);
    }];
    
    [self.rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.view).offset(15 * SCREENH6);
        make.top.mas_equalTo(self.view).offset(kStatusBarHeight + 10 * SCREENH6);
        make.width.mas_equalTo(23 * SCREENH6);
        make.height.mas_equalTo(23 * SCREENH6);
    }];
    
    [self.outButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.scrollView);
        make.top.mas_equalTo(self.collectionView.mas_bottom).offset(30 * SCREENH6);
        make.width.mas_equalTo(85 * SCREENH6);
        make.height.mas_equalTo(20 * SCREENH6);
        make.bottom.mas_equalTo(self.container).offset(-20 * SCREENH6);
    }];
}


- (void)clickSeverButton:(UIButton *)button{
    
    if (self.leftButton == button) {
        
        [self clickSeverceButton];
        
    }else{
        
        HiddenBar;
        
        NSNotiViewController * notiVC = [NSNotiViewController new];
        
        [self.navigationController pushViewController:notiVC animated:YES];
        
        ShowBar;
    }
    
}

- (void)clickItemButton:(NSString *)type WithMoney:(NSString *)money{
    
    if ([type isEqualToString:@"MyShop"]) {
        
        [[ZRNetworkTool sharedTool] getMerchantsStatusResultWithBlock:^(BOOL success, id responseData) {
            
            if (success) {
                
//                NSLog(@"responseData===%@",responseData);
                NSDictionary * dict = responseData[@"data"];
                
                int merchants_audit = [dict[@"merchants_audit"] intValue];
                //-1未审核  1为审核通过  0审核中   2为未通过
                if (merchants_audit == 1) {
                    
                    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

                    ShopTabBarController *tabs = [[ShopTabBarController alloc] init];
                    tabs.delegate = appDelegate;
                    appDelegate.window.rootViewController = tabs;
                    
                }else if (merchants_audit == 0){
                    
                    UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                                   message:@"审核中，请耐心等候"
                                                                            preferredStyle:UIAlertControllerStyleAlert];
                    
                    UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                          handler:^(UIAlertAction * action) {
                                                                              
                                                                          }];
                    
                    [alert addAction:defaultAction];
                    [self presentViewController:alert animated:YES completion:nil];
                }else if (merchants_audit == 2){
                    
                    HiddenBar;
                    
                    MerchantsStatusViewController * statusVC = [MerchantsStatusViewController new];
                    statusVC.why_failure = dict[@"merchants_why_failure"];
                    [self.navigationController pushViewController:statusVC animated:YES];
                    
                    ShowBar;
                }else{
                    
                    HiddenBar;
                    
                    ApplyforShopViewController * applyVC = [ApplyforShopViewController new];
                    
                    [self.navigationController pushViewController:applyVC animated:YES];
                    
                    ShowBar;
                }
            }
        }];
        
        

        
    }else if ([type isEqualToString:@"edit"]){
        
//        [self.navigationController setNavigationBarHidden:NO animated:YES];
        
        HiddenBar;
        
        EditViewController * editVC = [EditViewController new];
        
        editVC.dict = self.dict;
        
        [self.navigationController pushViewController:editVC animated:YES];
        
        ShowBar;
    }else if ([type isEqualToString:@"HistoryOrder"]){
        
        HiddenBar;
        MyOrderViewController * orderVC = [MyOrderViewController new];
        
        [self.navigationController pushViewController:orderVC animated:YES];
        
        ShowBar;
    }else if ([type isEqualToString:@"money"]){
        
        HiddenBar;
        MoneyViewController * moneyVC = [MoneyViewController new];
        //用户
        moneyVC.type = @"1";
        moneyVC.money = money;
        
        [self.navigationController pushViewController:moneyVC animated:YES];
        
        ShowBar;
    }else if ([type isEqualToString:@"inter"]){
        
        HiddenBar;
        MyIntegralViewController * interVC = [MyIntegralViewController new];
        
        
        [self.navigationController pushViewController:interVC animated:YES];
        
        ShowBar;
    }
}

- (void)clickSeverceButton{

    UIToolbar *toolbar = [[UIToolbar alloc]initWithFrame:[UIScreen mainScreen].bounds];
    //样式
    toolbar.barStyle = UIBarStyleBlackTranslucent;//半透明
    //透明度
    toolbar.alpha = 0.5f;
    toolbar.userInteractionEnabled = YES;
  
    UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
    [toolbar addGestureRecognizer:tapGR];

    self.toolbar = toolbar;
    [self.tabBarController.view addSubview:self.toolbar];

    UIView * helpView = [[UIView alloc] initWithFrame:CGRectMake(62.5 * SCREENH6, kScreenH/2 - 120 * SCREENH6, 250 * SCREENH6, 203 * SCREENH6)];

    helpView.backgroundColor = ZRWhiteColor;
    helpView.userInteractionEnabled = YES;
    helpView.layer.cornerRadius = 5 * SCREENH6;
    helpView.layer.masksToBounds = YES;

    self.helpView = helpView;

    [self.tabBarController.view addSubview:self.helpView];

    UILabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 8 * SCREENH6, 250 * SCREENH6, 30 * SCREENH6)];

    titleLabel.text = @"联系客服";
    titleLabel.textColor = ZRBlackColor;
    titleLabel.font = [UIFont systemFontOfSize:17 * SCREENH6];
    titleLabel.textAlignment = NSTextAlignmentCenter;

    [self.helpView addSubview:titleLabel];


    UIButton * msgButton = [[UIButton alloc] init];

    msgButton.tag = 2001;
    [msgButton setImage:[UIImage imageNamed:@"在线客服"] forState:UIControlStateNormal];
    [msgButton addTarget:self action:@selector(clickCallOrMsgToSeverice:) forControlEvents:UIControlEventTouchUpInside];

    [self.helpView addSubview:msgButton];

    UIButton * telButton = [[UIButton alloc] initWithFrame:CGRectMake(10 * SCREENH6, 96 * SCREENH6, 230 * SCREENH6, 30 * SCREENH6)];

    telButton.tag = 2002;
    [telButton setImage:[UIImage imageNamed:@"客服电话"] forState:UIControlStateNormal];
    [telButton addTarget:self action:@selector(clickCallOrMsgToSeverice:) forControlEvents:UIControlEventTouchUpInside];

    [self.helpView addSubview:telButton];
    
    UIButton * commitButton = [[UIButton alloc] init];
    
    commitButton.tag = 2003;
    [commitButton setImage:[UIImage imageNamed:@"常见问题"] forState:UIControlStateNormal];
    [commitButton addTarget:self action:@selector(clickCallOrMsgToSeverice:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.helpView addSubview:commitButton];


    UIButton * closeButton = [[UIButton alloc] initWithFrame:CGRectMake(50 * SCREENH6, 146 * SCREENH6, 150 * SCREENH6, 30 * SCREENH6)];

    closeButton.tag = 2004;
    [closeButton setImage:[UIImage imageNamed:@"关闭(1)"] forState:UIControlStateNormal];
    [closeButton addTarget:self action:@selector(clickCallOrMsgToSeverice:) forControlEvents:UIControlEventTouchUpInside];

    [self.helpView addSubview:closeButton];

//    [helpView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.mas_equalTo(self.view);
//        make.centerY.mas_equalTo(self.view).offset(20 * SCREENH6);
//        make.width.mas_equalTo(250 * SCREENH6);
//        make.height.mas_equalTo(203 * SCREENH6);
//    }];
//
//    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.mas_equalTo(helpView);
//        make.top.mas_equalTo(helpView).offset(15 * SCREENH6);
//    }];

    [commitButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(self.helpView);
        make.top.mas_equalTo(titleLabel.mas_bottom).offset(15 * SCREENH6);
        make.width.mas_equalTo(200 * SCREENH6);
        make.height.mas_equalTo(30 * SCREENH6);
    }];
    
    [msgButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.height.mas_equalTo(commitButton);
        make.top.mas_equalTo(commitButton.mas_bottom).offset(15 * SCREENH6);
    }];

    [telButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.height.mas_equalTo(msgButton);
        make.top.mas_equalTo(msgButton.mas_bottom).offset(15 * SCREENH6);
    }];

    [closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(titleLabel);
        make.trailing.mas_equalTo(self.helpView).offset(-10 * SCREENH6);
        make.width.height.mas_equalTo(25 * SCREENH6);
//        make.height.mas_equalTo(30 * SCREENH6);
    }];
}

- (void)tapAction{

    [self.toolbar removeFromSuperview];
    [self.helpView removeFromSuperview];
}
- (void)clickCallOrMsgToSeverice:(UIButton *)button{

    if (button.tag == 2001) {

        NSString * merchants_admin_phone = @"17781489591";

        [JMSGConversation createSingleConversationWithUsername:merchants_admin_phone completionHandler:^(id resultObject, NSError *error) {

            if (error == nil) {

                [self.toolbar removeFromSuperview];
                [self.helpView removeFromSuperview];

                HiddenBar;
                ChatRoomViewController * roomVC = [ChatRoomViewController new];

                roomVC.conversation = resultObject;

                [self.navigationController pushViewController:roomVC animated:YES];

                ShowBar;

            } else {

            }
        }];

    }else if (button.tag == 2002){

        NSString * str = @"tel:028-65279781";

        UIWebView * callWebview = [[UIWebView alloc] init];

        [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];

        [self.view addSubview:callWebview];

        [self.toolbar removeFromSuperview];
        [self.helpView removeFromSuperview];

    }else if (button.tag == 2003){
        
        [self.toolbar removeFromSuperview];
        [self.helpView removeFromSuperview];
        
        HiddenBar;
        CommitViewController * commitVC = [CommitViewController new];
        
        [self.navigationController pushViewController:commitVC animated:YES];
        
        ShowBar;
    }
    else if (button.tag == 2004){

        [self.toolbar removeFromSuperview];
        [self.helpView removeFromSuperview];
    }
}

- (void)didLeftNavButton{
    
    UIView * backView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    
    backView.backgroundColor = ZRBlackColor;
    backView.alpha = 0.4;
    UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(removeCouponView)];
    backView.userInteractionEnabled = YES;
    [backView addGestureRecognizer:tapGR];
    
    self.backView = backView;
    
    [self.tabBarController.view addSubview:self.backView];
    
    int yValue;
    
    if (iPhoneX) {
        
        yValue = kStatusBarHeight + kNavHeight + 120 * SCREENH6;
    }else{
        
        yValue = kStatusBarHeight + 120 * SCREENH6;
    }
    
    self.couponView = [[CouponView alloc] initWithFrame:CGRectMake(15 * SCREENH6, yValue, 345 * SCREENH6, 400 * SCREENH6)];
    
    self.couponView.homeCouponViewDelegate = self;
    self.couponView.layer.cornerRadius = 5;
    self.couponView.layer.masksToBounds = YES;
    
    [self.tabBarController.view addSubview:self.couponView];
}

- (void)removeCouponView{
    
    [self.backView removeFromSuperview];
    [self.couponView removeFromSuperview];
}

- (void)clickUseButtonWithShop_id:(NSString *)shop_id{
    
    if ([shop_id isEqualToString:@"0"]) {
        
        UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                       message:@"该券为全场通用券，在任何一家店铺都能使用"
                                                                preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                              handler:^(UIAlertAction * action) {
                                                                  
                                                              }];
        
        [alert addAction:defaultAction];
        [self presentViewController:alert animated:YES completion:nil];
    }else{
        
        HiddenBar;
        ShopDetailsViewController * detailsVC = [ShopDetailsViewController new];
        detailsVC.ID = shop_id;
        [self.navigationController pushViewController:detailsVC animated:YES];
        ShowBar;
    }
    
    [self.backView removeFromSuperview];
    [self.couponView removeFromSuperview];
}


- (void)clickOutButton{
    
    UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                   message:@"是否确认退出?"
                                                            preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault
                                                          handler:^(UIAlertAction * action) {
                                                              
                                                              NSUserDefaults *defatluts = [NSUserDefaults standardUserDefaults];
                                                              
                                                              NSDictionary *dictionary = [defatluts dictionaryRepresentation];
                                                              
                                                              for(NSString *key in [dictionary allKeys]){
                                                                  
                                                                  [defatluts removeObjectForKey:key];
                                                                  [defatluts synchronize];
                                                              }
                                                              
                                                              //                                                                  [self.navigationController setNavigationBarHidden:NO animated:YES];
                                                              /**
                                                               删除数据库表.
                                                               */
                                                              //                                                                  [People bg_drop:bg_tablename];
                                                              [NSArray bg_drop:nil];
                                                              
                                                              AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
                                                              
                                                              appDelegate.window.rootViewController = [LoginViewController new];
                                                          }];
    UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel
                                                         handler:^(UIAlertAction * action) {
                                                             
                                                         }];
    
    [alert addAction:defaultAction];
    [alert addAction:cancelAction];
    
    [self presentViewController:alert animated:YES completion:nil];

}


- (void)pushToEditVC{
    
    HiddenBar;
    
    EditViewController * editVC = [EditViewController new];
    
    editVC.dict = self.dict;
    
    [self.navigationController pushViewController:editVC animated:YES];
    
    ShowBar;
}

- (void)updateData{
    
    [self loadData];
}

@end
